package action.chap5;

import action.chap4.Dish;
import action.chap4.DishUtils;

import java.util.List;
import java.util.Optional;

public class Demo53 {
    public static void main(String[] args) {
        List<Dish> menus = DishUtils.getListDish();
        //流中是否有一个元素能匹配给定的谓词
        if (menus.stream().anyMatch(Dish::isVegetarian)) {
            System.out.println("anyMatch来了老弟");
        }
        if (menus.stream().allMatch(Dish::isVegetarian)) {
            System.out.println("allMatch来了老弟");
        }
        if (menus.stream().noneMatch(Dish::isVegetarian)) {
            System.out.println("noneMatch来了老弟");
        }
        //流水线将在后台进行优化使其只需走一遍，并在利用短路找到结果时立即结束。
        Optional<Dish> any = menus.stream().filter(Dish::isVegetarian).findAny();

        menus.stream().filter(Dish::isVegetarian).findAny().ifPresent(dish -> System.out.println(dish.getName()));
    }
}
